#include <stdlib.h>
#include <stdio.h>
#include <nds.h>

#include "common.h"

#include "version.h"

#if defined(Plugin)
#include "plugin.h"
#endif

#if defined(Library)
#include "library.h"
#endif

const char *_VERSION_STATES[]={
    "a%d",      // alpha #
    "b%d",      // beta #
    "rc%d",     // release candidate #
    "",         // normal

    "alpha",    // alpha
    "beta",     // beta
    "rc",       // release candidate
    ""          // normal
};

char _STRING_STATIC[VERSION_STATE_STR_MAX_LEN+1];

char *VERSION_STATE(ver_t v) {
    int ss=VERSION_STATE_STATE(v);
    int sn=VERSION_STATE_NUM(v);

#if defined(Plugin) || defined(Library)
    std->sprintf(
#else
    sprintf(
#endif
        _STRING_STATIC,                 // dest
        _VERSION_STATES[sn?ss:(ss+4)],  // format
        sn                              // argument
    );

    return _STRING_STATIC;
}

